package com.concurrency.countDownLatch;

import java.util.concurrent.CountDownLatch;

public class Worker extends Thread{
	CountDownLatch latch = null;
	
	public Worker(CountDownLatch latch){
		this.latch = latch;
	}

	public void run(){

		try {
			System.out.println(Thread.currentThread().getName()+"开始第一阶段工作。");
			Thread.sleep(4000);
			System.out.println(Thread.currentThread().getName()+"第一阶段工作完成。");
			latch.countDown();//latch计数器初始化为2，这里减一。
			System.out.println(Thread.currentThread().getName()+"开始第二阶段工作。");
			Thread.sleep(2000);
			System.out.println(Thread.currentThread().getName()+"第二阶段工作完成。");
			
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
